function sort(arr) {
    for(len = 1; len < arr.length; len ++) {
        const tmp = arr[len];
        let i = len - 1;
        while(i >= 0 && arr[i] > tmp) {
            arr[i + 1] = arr[i];
            i --
        }
        arr[i + 1] = tmp;
    }
}

function swap(arr, i, j) {
    const tmp = arr[i];
    arr[i] = arr[j];
    arr[j] = tmp
}

const demo = [9, 8, 1, 3, 5, 2, 7, 4, 6];
sort(demo);
console.log(demo);
